package cc.wsyw126.java.jvm.proxy.JDKProxy;

import cc.wsyw126.java.jvm.proxy.UserService;
import cc.wsyw126.java.jvm.proxy.UserServiceImpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * Created by Administrator on 2017/4/25.
 */
public class Main {
    public static void main(String[] args) {
        UserService userService = new UserServiceImpl();
        System.out.println("userService.getClass() = " + userService.getClass());
        InvocationHandler invocationHandler = new MyInvocationHandler(userService);
        UserService userServiceProxy = (UserService) Proxy.newProxyInstance(
                userService.getClass().getClassLoader(),
                userService.getClass().getInterfaces(),
                invocationHandler
        );
        Class<? extends UserService> aClass = userServiceProxy.getClass();
        System.out.println("aClass = " + aClass);
        System.out.println(userServiceProxy.getName(1));
        System.out.println(userServiceProxy.getAge(1));
    }
}
